import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
const store=new Vuex.Store({
    state:{
        todoList:[
            {
                id:1,
                name:"a"
            },
            {
                id:2,
                name:"b"
            },
            {
                id:3,
                name:"c"
            }
        ]
    },
    mutations:{
        add(state,val){
            state.todoList.splice(val.index,0,val.item)
            console.log(state.todoList)
        },
        delete(state,val){
            state.todoList.splice(val.index,1)
        },
        change(state,val){
            console.log(val)
            state.todoList[val.index].name=val.name
        }
    },
    getters:{
        findIndex:(state)=>(val)=>{
            return state.todoList.indexOf(val)
        }
    }
})
export default store